﻿// -------------------------------------------------------------------------
//    @FileName         :    MapDataEx.h
//    @Author           :    gaoyi
//    @Date             :    2025-03-24
//    @Email			:    445267987@qq.com
//    @Module           :    MapDataEx
//
// -------------------------------------------------------------------------

#pragma once

#include <E_City.nanopb.h>
#include <DescStore/CityMapDesc.h>
#include <NFLogicCommon/NFBaseDefine.h>

#include "proto_common_map.nanopb.h"
#include "NFServerComm/NFServerCommon/NFIDescStoreEx.h"
#include "NFServerComm/NFServerCommon/NFIDescTemplate.h"
#include "NFComm/NFObjCommon/NFResDb.h"
#include "NFComm/NFObjCommon/NFShmMgr.h"
#include "NFComm/NFShmStl/NFShmHashMap.h"
#include "NFComm/NFShmStl/NFShmVector.h"
#include "NFLogicCommon/NFDescStoreTypeDefines.h"
#include "NFGameCommon/tinyxml2.h"

#define MAX_NAVMESH_SIZE 1024*1024*3
#define MAP_NPC_GROUP_AVG_NUM 25
#define NPC_GROUP_NPC_AVG_NUM 2

class MapDataEx : public NFIDescTemplate<MapDataEx, MapDataDesc, EOT_CONST_MAP_DATA_EX_ID, MAX_LEVEL_DESC_RECORD_NUM>
{
public:
    MapDataEx();
    virtual ~MapDataEx();
    int CreateInit();
    int ResumeInit();

public:
    int Load(NFResDb* pDB) override;
    int CheckWhenAllDataLoaded() override;

    int GetNeedWarnLineMin() const override { return 0; }
public:
    static int LoadGroupNpc(MapDataDesc& mapDataDesc, int iMapDescID, const char* filename, const char* res_name);
    static int LoadLevel(MapDataDesc& mapDataDesc, int iMapDescID, const char* filename, const char* res_name);
    static int LoadScene(MapDataDesc& mapDataDesc, int iMapDescID, const char* pszMapDataPath, const char* scene_res_name);
    static int LoadNavmeshData(MapDataDesc& mapDataDesc, const char* pszMapDataPath, const char* scene_res_name, bool m_bIsNavmeshLoaded);

private:
    static int ReadNavmeshData(MapDataDesc& mapDataDesc, const char* szPath, const char* res_name, bool bReMakeNavmesh, bool m_bIsNavmeshLoaded);
    static int ReadElementSpawn(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementMovePlatform(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementLine(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementPath(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementSpawnGroup(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementStronghold(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementCrystalData(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementWeather(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementBehaviorBox(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementLevelCondition(MapDataDesc& mapDataDesc, tinyxml2::XMLElement* pElement);
    static int ReadElementSpawnNpc(int iMapDescID, SpawnNpc* pstNpc, tinyxml2::XMLElement* pElement);
private:
    int m_aiIndex[MAX_MAP_DESC_ID_VALUE];
    bool m_bLoadedNavmeshData;

    NFShmVector<SpawnGroup, MAX_LEVEL_DESC_RECORD_NUM * MAP_NPC_GROUP_AVG_NUM> m_astSpawnGroupPool;
    int m_iFreeGroup;

    NFShmVector<SpawnNpc, MAX_LEVEL_DESC_RECORD_NUM * MAP_NPC_GROUP_AVG_NUM * NPC_GROUP_NPC_AVG_NUM> m_astSpawnNpcPool;
    int m_iFreeNpc;
};
